﻿<?xml version="1.0" encoding="utf-8"?>
<DataModel 
  xmlns="http://SoftwareEngineering.com/Modeling/DataModeling"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:ms="clr-namespace:System;assembly=mscorlib, 4.0.0.0"
  Name="DemoAppModel"
  Namespace="DemoApp"
  InitType="DropIfModified"
  >
  <DataModel.EntityTypes>
    <EntityType Name="Role" EntitySetName="Roles">
      <Property Name="RoleId" Type="{x:Type ms:Guid}" IsKey="true">
        <HasDatabaseGeneratedOption>Identity</HasDatabaseGeneratedOption>
      </Property>
      <Property Name="Name" Type="{x:Type ms:String}" IsRequired="true">
        <HasMaxLength Length="60"/>
      </Property>
      <Property Name="IsAdmin" Type="{x:Type ms:Boolean}" IsRequired="true"/>
      <Reference Name="SecurableActions" EntityType="SecurableAction" OppositeReference="Roles" IsMultiple="true"/>
      <Reference Name="Users" EntityType="User" OppositeReference="Roles" IsMultiple="true"/>
    </EntityType>
    <EntityType Name="SecurableAction" EntitySetName="SecurableActions">
      <Property Name="SecurableActionId" Type="{x:Type ms:Guid}" IsKey="true">
        <HasDatabaseGeneratedOption>Identity</HasDatabaseGeneratedOption>
      </Property>
      <Property Name="Name" Type="{x:Type ms:String}" IsRequired="true">
        <HasMaxLength Length="60"/>
      </Property>
      <Reference Name="Roles" EntityType="Role" OppositeReference="SecurableActions" IsMultiple="true"/>
    </EntityType>
    <EntityType Name="User" IsAbstract="true" EntitySetName="Users" HierarchyType="TablePerType">
      <Property Name="UserId" Type="{x:Type ms:Guid}" IsKey="true">
        <HasDatabaseGeneratedOption>Identity</HasDatabaseGeneratedOption>
      </Property>
      <Property Name="UserName" Type="{x:Type ms:String}" IsRequired="true">
        <HasMaxLength Length="20"/>
      </Property>
      <Property Name="Password" Type="{x:Type ms:String}" IsRequired="true">
        <HasMaxLength Length="20"/>
      </Property>
      <Reference Name="Roles" EntityType="Role" OppositeReference="Users" IsMultiple="true"/>
      <Reference Name="Groups" EntityType="Group" OppositeReference="Users" IsMultiple="true"/>
      <Reference Name="CreatedSubjects" EntityType="Subject" OppositeReference="Creator" IsMultiple="true"/>
      <Reference Name="EditedSubjects" EntityType="Subject" OppositeReference="Editors" IsMultiple="true"/>
      <!--<Reference Name="Favorites" EntityType="Favorite" OppositeReference="User" IsMultiple="true"/>-->
    </EntityType>
    <EntityType Name="Person" BaseEntityType="User" EntitySetName="People">
      <Property Name="FirstName" Type="{x:Type ms:String}" IsRequired="true">
        <HasMaxLength Length="40"/>
      </Property>
      <Property Name="LastName" Type="{x:Type ms:String}" IsRequired="true">
        <HasMaxLength Length="60"/>
      </Property>
      <Property Name="Email" Type="{x:Type ms:String}" IsRequired="true">
        <HasMaxLength Length="260"/>
      </Property>
    </EntityType>
    <EntityType Name="Group" BaseEntityType="User" EntitySetName="Groups">
      <Reference Name="Users" EntityType="User" OppositeReference="Groups" IsMultiple="true"/>
    </EntityType>
    <EntityType Name="Subject" EntitySetName="Subjects">
      <Property Name="SubjectId" Type="{x:Type ms:Guid}" IsKey="true">
        <HasDatabaseGeneratedOption>Identity</HasDatabaseGeneratedOption>
      </Property>
      <Property Name="Url" Type="{x:Type ms:String}" IsRequired="true">
        <HasMaxLength Length="260"/>
      </Property>
      <Property Name="Title" Type="{x:Type ms:String}" IsRequired="true">
        <HasMaxLength Length="260"/>
      </Property>
      <Property Name="Description" Type="{x:Type ms:String}"/>
      <Property Name="ImageUrl" Type="{x:Type ms:String}">
        <HasMaxLength Length="260"/>
      </Property>
      <Property Name="CreateDate" Type="{x:Type ms:DateTime}" IsRequired="true"/>
      <Property Name="ModifyDate" Type="{x:Type ms:DateTime}" IsRequired="true"/>
      <Property Name="IsDisabled" Type="{x:Type ms:Boolean}" IsRequired="true"/>
      <Reference Name="Creator" EntityType="User" OppositeReference="CreatedSubjects" IsRequired="true"/>
      <Reference Name="Editors" EntityType="User" OppositeReference="EditedSubjects" IsMultiple="true"/>
      <Reference Name="ParentSubject" EntityType="Subject" OppositeReference="SubSubjects"/>
      <Reference Name="SubSubjects" EntityType="Subject" OppositeReference="ParentSubject" IsMultiple="true"/>
      <!--<Reference Name="Followers" EntityType="Favorite" OppositeReference="Subject" IsMultiple="true"/>-->
    </EntityType>
    <EntityType Name="Favorite" EntitySetName="Favorites">
      <UnidirectionalReference Name="User" IsKey="true" EntityType="User" IsMultiple="false" OppositeIsMultiple="true"/>
      <UnidirectionalReference Name="Subject" IsKey="true" EntityType="Subject" IsMultiple="false" OppositeIsMultiple="true"/>
      <Property Name="Vote" Type="{x:Type ms:Double}"/>
      <Reference Name="SuperFavorites" EntityType="FavoriteDerived" OppositeReference="SubFavorites" IsMultiple="true"/>
    </EntityType>
    <EntityType Name="FavoriteDerived" EntitySetName="FavoritesDerived" BaseEntityType="Favorite">
      <Property Name="DateOfCreation" Type="{x:Type ms:DateTime}"/>
      <Reference Name="SubFavorites" EntityType="Favorite" OppositeReference="SuperFavorites" IsMultiple="true"/>
    </EntityType>
  </DataModel.EntityTypes>
  <DataModel.DataInitialization>
    <Insert EntitySet="SecurableActions" Key="SecurableActions:Roles Create">
      <Setter Property="Name" Value="Role Create"/>
    </Insert>
    <Insert EntitySet="SecurableActions" Key="SecurableActions:Roles Delete">
      <Setter Property="Name" Value="Role Delete"/>
    </Insert>
    <Insert EntitySet="SecurableActions" Key="SecurableActions:Roles Read">
      <Setter Property="Name" Value="Role Read"/>
    </Insert>
    <Insert EntitySet="SecurableActions" Key="SecurableActions:Roles Read Name">
      <Setter Property="Name" Value="Role Read Name"/>
    </Insert>
    <Insert EntitySet="SecurableActions" Key="SecurableActions:Roles Read IsAdmin">
      <Setter Property="Name" Value="Role Read IsAdmin"/>
    </Insert>
    <Insert EntitySet="SecurableActions" Key="SecurableActions:Roles Read SecurableActions">
      <Setter Property="Name" Value="Role Read SecurableActions"/>
    </Insert>
    <Insert EntitySet="SecurableActions" Key="SecurableActions:Roles Update">
      <Setter Property="Name" Value="Role Update"/>
    </Insert>
    <Insert EntitySet="SecurableActions" Key="SecurableActions:Roles Update Name">
      <Setter Property="Name" Value="Role Update Name"/>
    </Insert>
    <Insert EntitySet="SecurableActions" Key="SecurableActions:Roles Update IsAdmin">
      <Setter Property="Name" Value="Role Update IsAdmin"/>
    </Insert>
    <Insert EntitySet="SecurableActions" Key="SecurableActions:Roles Update SecurableActions">
      <Setter Property="Name" Value="Role Update SecurableActions"/>
    </Insert>
    <Insert EntitySet="SecurableActions" Key="SecurableActions:SecurableActions Create">
      <Setter Property="Name" Value="Role Create"/>
    </Insert>
    <Insert EntitySet="SecurableActions" Key="SecurableActions:SecurableActions Delete">
      <Setter Property="Name" Value="Role Delete"/>
    </Insert>
    <Insert EntitySet="SecurableActions" Key="SecurableActions:SecurableActions Read">
      <Setter Property="Name" Value="Role Read"/>
    </Insert>
    <Insert EntitySet="SecurableActions" Key="SecurableActions:SecurableActions Read Name">
      <Setter Property="Name" Value="Role Read Name"/>
    </Insert>
    <Insert EntitySet="SecurableActions" Key="SecurableActions:SecurableActions Read Roles">
      <Setter Property="Name" Value="Role Read SecurableActions"/>
    </Insert>
    <Insert EntitySet="SecurableActions" Key="SecurableActions:SecurableActions Update">
      <Setter Property="Name" Value="Role Update"/>
    </Insert>
    <Insert EntitySet="SecurableActions" Key="SecurableActions:SecurableActions Update Name">
      <Setter Property="Name" Value="Role Update Name"/>
    </Insert>
    <Insert EntitySet="SecurableActions" Key="SecurableActions:SecurableActions Update Roles">
      <Setter Property="Name" Value="Role Update SecurableActions"/>
    </Insert>

    <Insert EntitySet="Roles" Key="Role:Admin">
      <Setter Property="Name" Value="Administrator"/>
      <Setter Property="IsAdmin" Value="true"/>
      <Setter Property="SecurableActions">
        <SetterValue Value="SecurableActions:Roles Create"/>
        <SetterValue Value="SecurableActions:Roles Delete"/>
        <SetterValue Value="SecurableActions:Roles Read"/>
        <SetterValue Value="SecurableActions:Roles Read Name"/>
        <SetterValue Value="SecurableActions:Roles Read IsAdmin"/>
        <SetterValue Value="SecurableActions:Roles Read SecurableActions"/>
        <SetterValue Value="SecurableActions:Roles Update"/>
        <SetterValue Value="SecurableActions:Roles Update Name"/>
        <SetterValue Value="SecurableActions:Roles Update IsAdmin"/>
        <SetterValue Value="SecurableActions:Roles Update SecurableActions"/>
        <SetterValue Value="SecurableActions:SecurableActions Create"/>
        <SetterValue Value="SecurableActions:SecurableActions Delete"/>
        <SetterValue Value="SecurableActions:SecurableActions Read"/>
        <SetterValue Value="SecurableActions:SecurableActions Read Name"/>
        <SetterValue Value="SecurableActions:SecurableActions Update"/>
        <SetterValue Value="SecurableActions:SecurableActions Update Name"/>
      </Setter>
    </Insert>
    <Insert EntitySet="Roles" Key="Role:Member">
      <Setter Property="Name" Value="Member"/>
      <Setter Property="IsAdmin" Value="false"/>
    </Insert>
  </DataModel.DataInitialization>
</DataModel>